--DO NOT MODIFY THIS FILE. IT IS ALWAYS OVERWRITTEN ON GENERATION.
--Data Schema For Version 0.0.0.0
--Generated on 2010-03-29 18:56:47

--CREATE TABLE [ALL_TYPES]
if not exists(select * from sysobjects where name = 'ALL_TYPES' and xtype = 'U')
CREATE TABLE [dbo].[ALL_TYPES] (
[all_type_id] [UniqueIdentifier] NOT NULL ,
[BigInt] [BigInt] NULL ,
[binary] [Binary] (50) NULL ,
[bit] [Bit] NULL ,
[char_test] [Char] (10) NULL ,
[computedNotPersisted] AS (([varchar]+[varcharmax])),
[computedPersisted] AS (([varchar]+[varcharmax])),
[date_test] [VarChar] (3) NULL ,
[datetime] [DateTime] NULL ,
[datetime2] [VarChar] (8) NULL ,
[datetimeoffset] [VarChar] (10) NULL ,
[decimal_test] [Decimal] (18, 0) NULL ,
[float_test] [Float] NULL ,
[geography] [VarChar] (max) NULL ,
[geometry] [VarChar] (max) NULL ,
[hierarchyid] [VarChar] (892) NULL ,
[image] [Image] NULL ,
[int_test] [Int] NULL ,
[money] [Money] NULL ,
[nchar] [NChar] (10) NULL ,
[ntext] [NText] NULL ,
[numeric] [Decimal] (18, 0) NULL ,
[nvarchar] [NVarChar] (50) NULL ,
[nvarcharmax] [NVarChar] (max) NULL ,
[real] [Real] NULL ,
[smalldatetime] [SmallDateTime] NULL ,
[smallint] [SmallInt] NULL ,
[smallmoney] [SmallMoney] NULL ,
[sql_variant] [VarChar] (max) NULL ,
[text] [Text] NULL ,
[time] [VarChar] (5) NULL ,
[tinyint] [TinyInt] NULL ,
[uniqueidentifier] [UniqueIdentifier] NULL ,
[varbinary] [VarBinary] (50) NULL ,
[varbinarymax] [VarBinary] (max) NULL ,
[varchar] [VarChar] (50) NULL ,
[varcharmax] [VarChar] (max) NULL ,
[xml] [VarChar] (max) NULL ,
[modified_by] [varchar] (50) NULL ,
[modified_date] [datetime] CONSTRAINT [DF__ALL_TYPES_MODIFIED_DATE] DEFAULT GetDate() NULL ,
[created_by] [varchar] (50) NULL ,
[created_date] [datetime] CONSTRAINT [DF__ALL_TYPES_CREATED_DATE] DEFAULT GetDate() NULL ,
[time_stamp] [timestamp] NOT NULL 
) ON [PRIMARY]


GO

--CREATE TABLE [IDENTITY_TEST]
if not exists(select * from sysobjects where name = 'IDENTITY_TEST' and xtype = 'U')
CREATE TABLE [dbo].[IDENTITY_TEST] (
[identity_test_id] [BigInt] IDENTITY (1, 1) NOT NULL ,
[name] [NVarChar] (50) NOT NULL ,
[modified_by] [varchar] (50) NULL ,
[modified_date] [datetime] CONSTRAINT [DF__IDENTITY_TEST_MODIFIED_DATE] DEFAULT GetDate() NULL ,
[created_by] [varchar] (50) NULL ,
[created_date] [datetime] CONSTRAINT [DF__IDENTITY_TEST_CREATED_DATE] DEFAULT GetDate() NULL ,
[time_stamp] [timestamp] NOT NULL 
) ON [PRIMARY]


GO

--CREATE TABLE [SIMPLE_CHILD]
if not exists(select * from sysobjects where name = 'SIMPLE_CHILD' and xtype = 'U')
CREATE TABLE [dbo].[SIMPLE_CHILD] (
[name] [NVarChar] (50) NULL ,
[simple_child_guid] [UniqueIdentifier] NOT NULL ,
[simple_table_guid] [UniqueIdentifier] NOT NULL ,
[modified_by] [varchar] (50) NULL ,
[modified_date] [datetime] CONSTRAINT [DF__SIMPLE_CHILD_MODIFIED_DATE] DEFAULT GetDate() NULL ,
[created_by] [varchar] (50) NULL ,
[created_date] [datetime] CONSTRAINT [DF__SIMPLE_CHILD_CREATED_DATE] DEFAULT GetDate() NULL ,
[time_stamp] [timestamp] NOT NULL 
) ON [PRIMARY]


GO

--CREATE TABLE [SIMPLE_TABLE]
if not exists(select * from sysobjects where name = 'SIMPLE_TABLE' and xtype = 'U')
CREATE TABLE [dbo].[SIMPLE_TABLE] (
[Name] [VarChar] (50) NULL ,
[simple_table_guid] [UniqueIdentifier] NOT NULL ,
[modified_by] [varchar] (50) NULL ,
[modified_date] [datetime] CONSTRAINT [DF__SIMPLE_TABLE_MODIFIED_DATE] DEFAULT GetDate() NULL ,
[created_by] [varchar] (50) NULL ,
[created_date] [datetime] CONSTRAINT [DF__SIMPLE_TABLE_CREATED_DATE] DEFAULT GetDate() NULL ,
[time_stamp] [timestamp] NOT NULL 
) ON [PRIMARY]


GO

--APPEND AUDIT TRAIL CREATE for Table [ALL_TYPES]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_by' and o.name = 'ALL_TYPES')
ALTER TABLE [ALL_TYPES] ADD [created_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_date' and o.name = 'ALL_TYPES')
ALTER TABLE [ALL_TYPES] ADD [created_date] [datetime] CONSTRAINT [DF__ALL_TYPES_CREATED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL MODIFY for Table [ALL_TYPES]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_by' and o.name = 'ALL_TYPES')
ALTER TABLE [ALL_TYPES] ADD [modified_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_date' and o.name = 'ALL_TYPES')
ALTER TABLE [ALL_TYPES] ADD [modified_date] [datetime] CONSTRAINT [DF__ALL_TYPES_MODIFIED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL TIMESTAMP for Table [ALL_TYPES]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'time_stamp' and o.name = 'ALL_TYPES')
ALTER TABLE [ALL_TYPES] ADD [time_stamp] [timestamp] NOT NULL

--APPEND AUDIT TRAIL CREATE for Table [IDENTITY_TEST]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_by' and o.name = 'IDENTITY_TEST')
ALTER TABLE [IDENTITY_TEST] ADD [created_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_date' and o.name = 'IDENTITY_TEST')
ALTER TABLE [IDENTITY_TEST] ADD [created_date] [datetime] CONSTRAINT [DF__IDENTITY_TEST_CREATED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL MODIFY for Table [IDENTITY_TEST]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_by' and o.name = 'IDENTITY_TEST')
ALTER TABLE [IDENTITY_TEST] ADD [modified_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_date' and o.name = 'IDENTITY_TEST')
ALTER TABLE [IDENTITY_TEST] ADD [modified_date] [datetime] CONSTRAINT [DF__IDENTITY_TEST_MODIFIED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL TIMESTAMP for Table [IDENTITY_TEST]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'time_stamp' and o.name = 'IDENTITY_TEST')
ALTER TABLE [IDENTITY_TEST] ADD [time_stamp] [timestamp] NOT NULL

--APPEND AUDIT TRAIL CREATE for Table [SIMPLE_CHILD]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_by' and o.name = 'SIMPLE_CHILD')
ALTER TABLE [SIMPLE_CHILD] ADD [created_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_date' and o.name = 'SIMPLE_CHILD')
ALTER TABLE [SIMPLE_CHILD] ADD [created_date] [datetime] CONSTRAINT [DF__SIMPLE_CHILD_CREATED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL MODIFY for Table [SIMPLE_CHILD]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_by' and o.name = 'SIMPLE_CHILD')
ALTER TABLE [SIMPLE_CHILD] ADD [modified_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_date' and o.name = 'SIMPLE_CHILD')
ALTER TABLE [SIMPLE_CHILD] ADD [modified_date] [datetime] CONSTRAINT [DF__SIMPLE_CHILD_MODIFIED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL TIMESTAMP for Table [SIMPLE_CHILD]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'time_stamp' and o.name = 'SIMPLE_CHILD')
ALTER TABLE [SIMPLE_CHILD] ADD [time_stamp] [timestamp] NOT NULL

--APPEND AUDIT TRAIL CREATE for Table [SIMPLE_TABLE]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_by' and o.name = 'SIMPLE_TABLE')
ALTER TABLE [SIMPLE_TABLE] ADD [created_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'created_date' and o.name = 'SIMPLE_TABLE')
ALTER TABLE [SIMPLE_TABLE] ADD [created_date] [datetime] CONSTRAINT [DF__SIMPLE_TABLE_CREATED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL MODIFY for Table [SIMPLE_TABLE]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_by' and o.name = 'SIMPLE_TABLE')
ALTER TABLE [SIMPLE_TABLE] ADD [modified_by] [varchar] (50) NULL
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'modified_date' and o.name = 'SIMPLE_TABLE')
ALTER TABLE [SIMPLE_TABLE] ADD [modified_date] [datetime] CONSTRAINT [DF__SIMPLE_TABLE_MODIFIED_DATE] DEFAULT GetDate() NULL

--APPEND AUDIT TRAIL TIMESTAMP for Table [SIMPLE_TABLE]
if not exists (select * from syscolumns c inner join sysobjects o on c.id = o.id where c.name = 'time_stamp' and o.name = 'SIMPLE_TABLE')
ALTER TABLE [SIMPLE_TABLE] ADD [time_stamp] [timestamp] NOT NULL

--PRIMARY KEY FOR TABLE [ALL_TYPES]
if not exists(select * from sysobjects where name = 'PK_ALL_TYPES' and xtype = 'PK')
ALTER TABLE [dbo].[ALL_TYPES] WITH NOCHECK ADD 
CONSTRAINT [PK_ALL_TYPES] PRIMARY KEY CLUSTERED 
(
	[all_type_id]
) ON [PRIMARY] 
GO

--PRIMARY KEY FOR TABLE [IDENTITY_TEST]
if not exists(select * from sysobjects where name = 'PK_IDENTITY_TEST' and xtype = 'PK')
ALTER TABLE [dbo].[IDENTITY_TEST] WITH NOCHECK ADD 
CONSTRAINT [PK_IDENTITY_TEST] PRIMARY KEY CLUSTERED 
(
	[identity_test_id]
) ON [PRIMARY] 
GO

--PRIMARY KEY FOR TABLE [SIMPLE_CHILD]
if not exists(select * from sysobjects where name = 'PK_SIMPLE_CHILD' and xtype = 'PK')
ALTER TABLE [dbo].[SIMPLE_CHILD] WITH NOCHECK ADD 
CONSTRAINT [PK_SIMPLE_CHILD] PRIMARY KEY CLUSTERED 
(
	[simple_child_guid]
) ON [PRIMARY] 
GO

--PRIMARY KEY FOR TABLE [SIMPLE_TABLE]
if not exists(select * from sysobjects where name = 'PK_SIMPLE_TABLE' and xtype = 'PK')
ALTER TABLE [dbo].[SIMPLE_TABLE] WITH NOCHECK ADD 
CONSTRAINT [PK_SIMPLE_TABLE] PRIMARY KEY CLUSTERED 
(
	[simple_table_guid]
) ON [PRIMARY] 
GO

--FOREIGN KEY RELATIONSHIP [SIMPLE_TABLE] -> [SIMPLE_CHILD] ([SIMPLE_TABLE].[simple_table_guid] -> [SIMPLE_CHILD].[simple_table_guid])
if not exists(select * from sysobjects where name = 'FK__SIMPLE_CHILD_SIMPLE_TABLE' and xtype = 'F')
ALTER TABLE [dbo].[SIMPLE_CHILD] ADD 
CONSTRAINT [FK__SIMPLE_CHILD_SIMPLE_TABLE] FOREIGN KEY 
(
		[simple_table_guid]
) REFERENCES [dbo].[SIMPLE_TABLE] (
		[simple_table_guid]
)
GO


--DROP ANY AUDIT TRIGGERS FOR [ALL_TYPES]
if exists(select * from sysobjects where name = '__TR_ALL_TYPES__INSERT' AND xtype = 'TR')
DROP TRIGGER [__TR_ALL_TYPES__INSERT]
GO
if exists(select * from sysobjects where name = '__TR_ALL_TYPES__UPDATE' AND xtype = 'TR')
DROP TRIGGER [__TR_ALL_TYPES__UPDATE]
GO
if exists(select * from sysobjects where name = '__TR_ALL_TYPES__DELETE' AND xtype = 'TR')
DROP TRIGGER [__TR_ALL_TYPES__DELETE]
GO

--DROP ANY AUDIT TRIGGERS FOR [IDENTITY_TEST]
if exists(select * from sysobjects where name = '__TR_IDENTITY_TEST__INSERT' AND xtype = 'TR')
DROP TRIGGER [__TR_IDENTITY_TEST__INSERT]
GO
if exists(select * from sysobjects where name = '__TR_IDENTITY_TEST__UPDATE' AND xtype = 'TR')
DROP TRIGGER [__TR_IDENTITY_TEST__UPDATE]
GO
if exists(select * from sysobjects where name = '__TR_IDENTITY_TEST__DELETE' AND xtype = 'TR')
DROP TRIGGER [__TR_IDENTITY_TEST__DELETE]
GO

--DROP ANY AUDIT TRIGGERS FOR [SIMPLE_CHILD]
if exists(select * from sysobjects where name = '__TR_SIMPLE_CHILD__INSERT' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_CHILD__INSERT]
GO
if exists(select * from sysobjects where name = '__TR_SIMPLE_CHILD__UPDATE' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_CHILD__UPDATE]
GO
if exists(select * from sysobjects where name = '__TR_SIMPLE_CHILD__DELETE' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_CHILD__DELETE]
GO

--DROP ANY AUDIT TRIGGERS FOR [SIMPLE_TABLE]
if exists(select * from sysobjects where name = '__TR_SIMPLE_TABLE__INSERT' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_TABLE__INSERT]
GO
if exists(select * from sysobjects where name = '__TR_SIMPLE_TABLE__UPDATE' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_TABLE__UPDATE]
GO
if exists(select * from sysobjects where name = '__TR_SIMPLE_TABLE__DELETE' AND xtype = 'TR')
DROP TRIGGER [__TR_SIMPLE_TABLE__DELETE]
GO

